package com.wenlin.myproduction.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.util.ValCommon;
import com.wenlin.myproduction.widget.RoundCircleGradientProgress;
import com.wenlin.myproduction.widget.RoundCircleProgress;

import butterknife.BindView;
import butterknife.OnClick;

public class RoundCircleGradientProgressActivity extends BaseSwipeActivity {
    @BindView(R.id.rcp)
    RoundCircleProgress rcp;
    @BindView(R.id.rcp2)
    RoundCircleGradientProgress rcp2;

    private int percent;
    private int i = 11;
    private CountDownTimer timer;

    @Override
    public int getContentView() {
        return R.layout.activity_round_circle_gradient_progress;
    }

    public static void start(BaseActivity activity) {
        Intent intent = new Intent(activity, RoundCircleGradientProgressActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(ValCommon.ROUND_CIRCLE_GRADIENT_PROGRESS);
        timer = new CountDownTimer(Integer.MAX_VALUE, 999) {
            @Override
            public void onTick(long millisUntilFinished) {
                i = i - 1;
                if (i < 0) i += 10;
                UI.setProgress(rcp, 100 - i * 10);
            }

            @Override
            public void onFinish() {

            }
        }.start();
    }

    @Override
    protected void onDestroy() {
        timer.cancel();
        timer = null;
        super.onDestroy();
    }

    @OnClick({R.id.tv_add})
    void click(View view) {
        switch (view.getId()) {
            case R.id.tv_add:
                percent += 10;
                if (percent > 100) percent -= 100;
                UI.setProgress(rcp2, percent);
                break;
            default:
        }
    }
}
